package com.freewater.springboot.demo.aop.api.advices.after;

import org.aopalliance.aop.Advice;
import org.aopalliance.intercept.MethodInterceptor;
import org.springframework.aop.Advisor;
import org.springframework.aop.framework.adapter.AdvisorAdapter;
import org.springframework.lang.NonNull;

/**
 * 适配器：把AfterFinalAdvice转换为MethodInterceptor（MethodAfterFinalAdviceInterceptor）
 */
public class AfterFinalAdviceAdaptor implements AdvisorAdapter {

    @Override
    public boolean supportsAdvice(@NonNull Advice advice) {
        return advice instanceof AfterFinalAdvice;
    }

    @Override
    public @NonNull MethodInterceptor getInterceptor(Advisor advisor) {
        AfterFinalAdvice afterFinalAdvice = (AfterFinalAdvice) advisor.getAdvice();
        return new MethodAfterFinalAdviceInterceptor(afterFinalAdvice);
    }
}
